package com.alameda.controller.login;

import com.alameda.api.user.UserService;
import com.alameda.result.Result;
import com.alameda.user.dto.UserDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 系统入口模块 前端控制层
 *
 * @author Lv
 * @date 2024/2/19
 */
@Api(tags = "系统入口模块")
@RestController
@RequestMapping("/airborne")
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 注册账号
     *
     * @param userDTO 用户数据传递对象
     * @return
     */
    @ApiOperation("注册账号")
    @PostMapping("/register")
    public Result<?> register(@RequestBody UserDTO userDTO) {
        return Result.success(userService.register(userDTO));
    }

    /**
     * 登录系统
     *
     * @param userDTO 用户数据传递对象
     * @return
     */
    @ApiOperation("登录系统")
    @PostMapping("/login")
    public Result<?> login(@RequestBody UserDTO userDTO) {
        return Result.success(userService.login(userDTO));
    }

    /**
     * 生成验证码
     *
     * @return
     */
    @ApiOperation("生成验证码")
    @GetMapping("/get_img_code")
    public Result<?> getImageCode() {
        return Result.success(userService.getImageCode());
    }

    /**
     * 退出登录
     *
     * @return
     */
    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public Result<?> logout() {
        return Result.success(userService.logout());
    }
}
